package cn.demo.cm.service.impl;

import java.time.LocalDateTime;
import java.util.List;

import cn.demo.common.utils.ObjUtils;
import cn.demo.common.utils.SecurityUtils;
import cn.demo.common.utils.StringUtils;
import com.mybatisflex.core.paginate.Page;
import cn.demo.common.core.page.PageQuery;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import cn.demo.cm.mapper.CmComplaintMapper;
import cn.demo.cm.domain.CmComplaint;
import cn.demo.cm.service.ICmComplaintService;

/**
 * 举报投诉Service业务层处理
 *
 * @author xtjun
 * @date 2024-06-06
 */
@Service
public class CmComplaintServiceImpl extends ServiceImpl<CmComplaintMapper, CmComplaint> implements ICmComplaintService {
    @Resource
    private CmComplaintMapper cmComplaintMapper;
    /**
     * 查询举报投诉
     *
     * @param id 举报投诉主键
     * @return 举报投诉
     */
    @Override
    public CmComplaint selectCmComplaintById(String id) {
        return cmComplaintMapper.selectOneById(id);
    }

    /**
     * 查询举报投诉列表
     *
     * @param cmComplaint 举报投诉
     * @return 举报投诉
     */
    @Override
    public Page<CmComplaint> selectCmComplaintPage(CmComplaint cmComplaint, PageQuery pageQuery) {
        return cmComplaintMapper.paginate(pageQuery.build(), QueryWrapper.create(cmComplaint,CmComplaint.operators));
    }
    @Override
    public List<CmComplaint> selectCmComplaintList(CmComplaint cmComplaint) {
        return cmComplaintMapper.selectListByQuery(QueryWrapper.create(cmComplaint,CmComplaint.operators));
    }

    /**
     * 新增举报投诉
     *
     * @param cmComplaint 举报投诉
     * @return 结果
     */
    @Override
    public int insertCmComplaint(CmComplaint cmComplaint) {
        return cmComplaintMapper.insert(cmComplaint);
    }

    /**
     * 修改举报投诉
     *
     * @param cmComplaint 举报投诉
     * @return 结果
     */
    @Override
    public int updateCmComplaint(CmComplaint cmComplaint) {
        if (null != cmComplaint.getIsHandle() && cmComplaint.getIsHandle() > 0) {
            if (ObjUtils.isEmpty(cmComplaint.getHandleTime())) cmComplaint.setHandleTime(LocalDateTime.now());
            if (StringUtils.isEmpty(cmComplaint.getHandleUser())) cmComplaint.setHandleUser(SecurityUtils.getUsername());
        }
        return cmComplaintMapper.update(cmComplaint);
    }

    /**
     * 批量删除举报投诉
     *
     * @param ids 需要删除的举报投诉主键
     * @return 结果
     */
    @Override
    public int deleteCmComplaintByIds(List<String> ids) {
        return cmComplaintMapper.deleteBatchByIds(ids);
    }

    /**
     * 删除举报投诉信息
     *
     * @param id 举报投诉主键
     * @return 结果
     */
    @Override
    public int deleteCmComplaintById(String id) {
        return cmComplaintMapper.deleteById(id);
    }
}
